//
//  define.h
//  TestView
//
//  Created by lk@wxm on 2024/12/4.
//

// 全局工具类宏定义

#ifndef define_h
#define define_h



#define isConectUrl 0

//获取系统对象
#define kApplication        [UIApplication sharedApplication]
#define kAppWindow          [UIApplication sharedApplication].delegate.window
#define kAppDelegate        [AppDelegate shareAppDelegate]
#define kRootViewController [UIApplication sharedApplication].delegate.window.rootViewController
#define kUserDefaults       [NSUserDefaults standardUserDefaults]
#define kNotificationCenter [NSNotificationCenter defaultCenter]

#define kStatusBarHeight [[UIApplication sharedApplication] statusBarFrame].size.height
#define NAV_HEIGHT ([[UIScreen mainScreen] bounds].size.height>=812)?88:64
#define kNavBarHeight 44.0
#define kTabBarHeight ([[UIApplication sharedApplication] statusBarFrame].size.height>20?83:49)
#define kTopHeight (kStatusBarHeight + kNavBarHeight)
#define kTopBarHeight (KScreenHeight >= 812.0 ? 88 : 64) //导航栏高度

//获取自己(避免循环引用)

//强弱引用

#define kWeakSelf(type)  __weak typeof(type) weak##type = type;
#define kStrongSelf(type) __strong typeof(type) type = weak##type;

//获取屏幕宽高
#define KScreenWidth ([[UIScreen mainScreen] bounds].size.width)
#define KScreenHeight [[UIScreen mainScreen] bounds].size.height

#define kScreen_Bounds [UIScreen mainScreen].bounds
#define UIScreenWidthScale KScreenWidth/(IS_PhoneXAll?(1334.0f):1334.0f)
#define UIScreenHeightScale KScreenHeight/750.0f

#define UIMScreenWidthScale KScreenWidth/375.0f
#define UIMScreenHeightScale KScreenHeight/667.0f
//根据ip6的屏幕来拉伸
#define kRealValue(with) ((with)*(UIScreenWidthScale))
#define kRealHeightValue(with) ((with)*(UIScreenHeightScale))

#define mRealValue(with) ((with)*(UIMScreenWidthScale))
#define mRealHeightValue(with) ((with)*(UIMScreenHeightScale))

#define SafeBarHeight ( IS_PhoneXAll ? 44 :0 )

#define SafeBottomBarHeight ( IS_PhoneXAll ? 34 :0 )
//导航栏高度
#define TopBarHeight (KScreenHeight == 812.0 ? 88 : 64)
//底部安全区域高度
#define bottomBarHeight (KScreenHeight == 812.0 ? 49 + 34 :49)


//View 圆角和加边框
#define ViewBorderRadius(View, Radius, Width, Color)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES];\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]]

// View 圆角
#define ViewRadius(View, Radius)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES]

//阴影
#define ViewShoadowRadius(View, Radius, Width, Color)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setShadowColor:Color.CGColor];\
[View.layer setShadowOffset:CGSizeMake(1, 2)];\
[View.layer setShadowOpacity:0.4];\
[View.layer setShadowRadius:(Width*UIScreenWidthScale)]


//property 属性快速声明 别用宏定义了，使用代码块+快捷键实现吧

// 当前系统版本
#define CurrentSystemVersion [[UIDevice currentDevice].systemVersion doubleValue]
/** 程序版本号 */

#define APP_VERSION [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]

//当前语言
//#define CurrentLanguage (［NSLocale preferredLanguages] objectAtIndex:0])

//-------------------打印日志-------------------------
//DEBUG  模式下打印日志,当前行
#ifdef DEBUG

#define MLog(fmt, ...) NSLog((@"[文件名:%s]" "[行号:%d] \n" fmt), __FILE__, __LINE__, ##__VA_ARGS__);
#else

#define MLog(...);
#endif

//拼接字符串
#define NSStringFormat(format,...) [NSString stringWithFormat:format,##__VA_ARGS__]

//颜色
#define kNavTitleColor HEXCOLOR(0x485E6E)
#define KClearColor [UIColor clearColor]
#define KWhiteColor [UIColor whiteColor]
#define KBlackColor [UIColor blackColor]
#define KGrayColor [UIColor grayColor]
#define KGray2Color [UIColor lightGrayColor]
#define KBlueColor [UIColor blueColor]
#define KRedColor [UIColor redColor]
#define KRGBColor(redcolor,greencolor,bluecolor) [UIColor colorWithRed:redcolor/255.0 green:greencolor/255.0 blue:bluecolor/255.0 alpha:1]
#define kRandomColor    KRGBColor(arc4random_uniform(256),arc4random_uniform(256),arc4random_uniform(256))        //随机色生成
#define HEXCOLOR(hex) [UIColor colorWithRed:((hex>>16)&0xFF)/255.0 green:((hex>>8)&0xFF)/255.0 blue:((hex)&0xFF)/255.0 alpha:1.0]
#define COLOR_RGB(rgbValue,a) [UIColor colorWithRed:((float)(((rgbValue) & 0xFF0000) >> 16))/255.0 green:((float)(((rgbValue) & 0xFF00)>>8))/255.0 blue: ((float)((rgbValue) & 0xFF))/255.0 alpha:(a)]
#define RGBA(r,g,b,a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]


//字体
#define FontCuYuan @"FZY4K--GBK1-0"
#define RealBOLDSYSTEMFONT(FONTSIZE)[UIFont boldSystemFontOfSize:FONTSIZE/2.1  +FontSizeScale]
#define RealSYSTEMFONT(FONTSIZE)    [UIFont systemFontOfSize:FONTSIZE/2.1  +FontSizeScale]
#define RealFONT(FONTSIZE)    [UIFont systemFontOfSize:FONTSIZE/2.1  +FontSizeScale]

#define BOLDSYSTEMFONT(FONTSIZE)[UIFont fontWithName:@"Helvetica-Bold" size:(FONTSIZE/2.1  +FontSizeScale)]
#define SYSTEMFONT(FONTSIZE)    [UIFont systemFontOfSize:FONTSIZE/FONTSIZE/2.1  +FontSizeScale]

#define FONTNAME(FONTNAME,FONTSIZE)  [UIFont fontWithName:FONTNAME size:(FONTSIZE/2.1  +FontSizeScale)]
#define FONT(FONTSIZE)    [UIFont systemFontOfSize:FONTSIZE/2.1  +FontSizeScale]
#define FontSizeScale (KScreenHeight > 320 ? KScreenHeight > 375 ? IS_IPAD ? 6: 2 : 1 : -3)
//#define FontSizeScale ( IS_IPAD ? IS_PhoneXAll? IS_IPHONE_6P? :8 :3: 2:1)
//中文字体
#define CHINESE_FONT_NAME  @"Heiti SC"
#define CHINESE_SYSTEM(x) [UIFont fontWithName:CHINESE_FONT_NAME size:x]

#define GET_URL(url)  [NSURL URLWithString:url]
//定义UIImage对象
#define ImageWithFile(_pointer) [UIImage imageWithContentsOfFile:([[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@@%dx", _pointer, (int)[UIScreen mainScreen].nativeScale] ofType:@"png"])]
#define IMAGE_NAMED(name) [UIImage imageNamed:name]

//数据验证
#define StrValid(f) (f!=nil && [f isKindOfClass:[NSString class]] && ![f isEqualToString:@""] && ![f isEqualToString:@"(null)"] && ![f isEqualToString:@"<null>"] && ![f isEqualToString:@"null"] && ![f isKindOfClass:[NSNull class]])
#define SafeStr(f) (StrValid(f) ? f:@"")
#define HasString(str,key) ([str rangeOfString:key].location!=NSNotFound)

#define SafeGetStringValue(object) ((![object isKindOfClass:[NSNull class]] && object!=nil)?([object isKindOfClass:[NSString class]]?object:[object stringValue]):@"")

#define ValidStr(f) StrValid(f)
#define ValidDict(f) (f!= nil && [f isKindOfClass:[NSDictionary class]] && [f isKindOfClass:[NSNull class]] ==  NO)
#define ValidArray(f) (f!=nil && [f isKindOfClass:[NSArray class]] && [f count]>0 && [f isKindOfClass:[NSNull class]] ==  NO)
#define ValidNum(f) (f!=nil && [f isKindOfClass:[NSNumber class]] && [f isKindOfClass:[NSNull class]]  ==  NO)
#define ValidClass(f,cls) (f!=nil && [f isKindOfClass:[cls class]] && [f isKindOfClass:[NSNull class]] ==  NO)
#define ValidData(f) (f!=nil && [f isKindOfClass:[NSData class]] && [f isKindOfClass:[NSNull class]]  ==  NO)

//获取一段时间间隔
#define kStartTime CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();
#define kEndTime  NSLog(@"Time: %f", CFAbsoluteTimeGetCurrent() - start)
#define ToastDuration 2.0

//打印当前方法名
#define ITTDPRINTMETHODNAME() ITTDPRINT(@"%s", __PRETTY_FUNCTION__)

//获取图片资源
#define GetImage(imageName) [UIImage imageNamed:[NSString stringWithFormat:@"%@",imageName]]
#define GetBunldImage(imageName)  [UIImage imageWithContentsOfFile:[[NSBundle bundleForClass:self.class] pathForResource:imageName ofType:nil inDirectory:[NSString stringWithFormat:@"%@.bundle", [NSBundle bundleForClass:self.class].infoDictionary[@"CFBundleName"]]]];

#define GetMathPlusBunldeImage(imageName)  [YYImage imageWithContentsOfFile:self.imageWithFileName(imageName)];

//发送通知
#define KPostNotification(name,obj) [[NSNotificationCenter defaultCenter] postNotificationName:name object:obj];

//默认多语言表
#define RS_CURRENT_LANGUAGE_TABLE  [[NSUserDefaults standardUserDefaults] objectForKey:@"LanguageSwtich"]?[[NSUserDefaults standardUserDefaults] objectForKey:@"LanguageSwtich"]:@"zh-Hans"

//单例化一个类
#define SINGLETON_FOR_HEADER(className) \
\
+ (className *)shared##className;

#define SINGLETON_FOR_CLASS(className) \
\
+ (className *)shared##className { \
static className *shared##className = nil; \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
shared##className = [[self alloc] init]; \
}); \
return shared##className; \
}

#define GetGradeStr \
\
- (NSString *)GetGradeStrWithCode:(NSString *)grade { \
if([grade isEqualToString:@"g1"] ){return @"一年级";} \
else if([grade isEqualToString:@"g2"] ){return @"二年级";} \
else if([grade isEqualToString:@"g3"] ){return @"三年级";} \
else if([grade isEqualToString:@"g4"] ){return @"四年级";} \
else if([grade isEqualToString:@"g5"] ){return @"五年级";} \
else if([grade isEqualToString:@"g6"] ){return @"六年级";} \
else {return @"幼升小";}\
}

//判断机型
/*判断手机大小*/
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)

#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
#define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH, SCREEN_HEIGHT))
#define SCREEN_MIN_LENGTH (MIN(SCREEN_WIDTH, SCREEN_HEIGHT))

#define IS_IPHONE_4_OR_LESS (IS_IPHONE && SCREEN_MAX_LENGTH < 568.0)
#define IS_IPHONE_5 (IS_IPHONE && SCREEN_MAX_LENGTH == 568.0)
#define IS_IPHONE_6 (IS_IPHONE && SCREEN_MAX_LENGTH == 667.0)
#define IS_IPHONE_6P (IS_IPHONE && SCREEN_MAX_LENGTH == 736.0)
//判断iPhoneX，Xs（iPhoneX，iPhoneXs）
#define IS_IPHONE_X ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) && !IS_IPAD : NO)
//判断iPhoneXr
#define IS_IPHONE_Xr ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(828, 1792), [[UIScreen mainScreen] currentMode].size) && !IS_IPAD : NO)

//判断iPhoneXsMax
#define IS_IPHONE_Xs_Max ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2688), [[UIScreen mainScreen] currentMode].size)&& !IS_IPAD : NO)

//判断iPhoneX所有系列
#define IS_PhoneXAll (IS_IPHONE_X || IS_IPHONE_Xr || IS_IPHONE_Xs_Max || IPHONE_X )

#define IPHONE_X \
({BOOL isPhoneX = NO;\
if (@available(iOS 11.0, *)) {\
isPhoneX = [[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom > 0.0;\
}\
(isPhoneX);})

//Library/Caches 文件路径
#define FilePath ([[NSFileManager defaultManager] URLForDirectory:NSCachesDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil])
//获取temp
#define kPathTemp NSTemporaryDirectory()
//获取沙盒 Document
#define kPathDocument [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]
//获取沙盒 Cache
#define kPathCache    [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]

#define kVideoListPath [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:@"VideoList.data"]

//#define kGameKnowNumberListPath [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:@"GameKnowNumberList.data"]
//#define kGameOperationNumberListPath [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:@"GameOperationNumberList.data"]
//#define kGameThoughtNumberListPath [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:@"GameThoughtNumberList.data"]

//在Main线程上运行
#define DISPATCH_ON_MAIN_THREAD(mainQueueBlock) dispatch_async(dispatch_get_main_queue(), mainQueueBlock);

//在Global Queue上运行
#define DISPATCH_ON_GLOBAL_QUEUE_HIGH(globalQueueBlocl) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), globalQueueBlocl);
#define DISPATCH_ON_GLOBAL_QUEUE_DEFAULT(globalQueueBlocl) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), globalQueueBlocl);
#define DISPATCH_ON_GLOBAL_QUEUE_LOW(globalQueueBlocl) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), globalQueueBlocl);
#define DISPATCH_ON_GLOBAL_QUEUE_BACKGROUND(globalQueueBlocl) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), globalQueueBlocl);

//根据userid查找指定的本地数据
#define kSearchUserDataList(table,userid) [NSString stringWithFormat:@"SELECT * FROM %@ WHERE code = '%@' ;",table,userid]

/****************************************下面sql没有用到，是以前的聊天功能的业务sql语句*******************************************************/
/*
//根据date（时间戳）查找发送状态为发送中的数据
#define kSearchModelWithDate(table,date,toId) [NSString stringWithFormat:@"SELECT * FROM %@ WHERE  date = '%@' AND toId = '%@'  and status = 1;",table,date,toId]
//根据date（时间戳）查找具体的一条未读数据
#define kSearchAMessageWithDate(table,toId) [NSString stringWithFormat:@"SELECT * FROM %@ WHERE  toId = '%@' and isRead = 0;",table,toId]
//根据指定ID 查找最新一条数据
#define kSearchANewsMessageWithToId(table,toId) [NSString stringWithFormat:@"select * from %@ where toId = '%@' and id in (select max(id) from LHMessageModel group by toId)",table,toId]

//根据date（时间戳）查找发送状态为发送失败的数据
#define kDeleteAMessageWithDate(table,date) [NSString stringWithFormat:@"SELECT * FROM %@ WHERE  date = '%@'  and status = 3;",table,date]
//查找消息列表（王学明写的）现在用的
#define kSearchMessageAndGroupList(table,userId,table1) [NSString stringWithFormat:@"select * from %@ where (toId <> '%@' and (fromId = '%@') or ((SELECT LENGTH(toId) > 8) and ( toId  in  (select groupid from %@ where userid = '%@') )or ( fromId  in  (select groupid from %@ where userid = '%@')) ))  and id in (select max(id) from %@ group by toId) ORDER BY date DESC;",table,userId,userId,table1,userId,table1,userId,table]
//测试用的查出所有的关系当前用户的单人聊天以及所有的本机上的群聊天
#define kSearchMessageAllList(table,userId) [NSString stringWithFormat:@"select * from %@ where (toId <> '%@' and (fromId = '%@') or (SELECT LENGTH(toId) > 8))  and id in (select max(id) from %@ group by toId) ORDER BY date DESC;",table,userId,userId,table]
//测试用的查出
#define kSearchUserList(table,userId,table1) [NSString stringWithFormat:@" select * from %@ where  toId  in  (select groupid from %@ where userid = '%@') or  fromId  in  (select groupid from %@ where userid = '%@') ",table,table1,userId,table1,userId]
//测试用的查出当前用户所有的群组id
#define kSearchMyUserList(table,userId) [NSString stringWithFormat:@"select  *  from %@ where userid = '%@' ",table,userId]

//查找置顶消息
#define kSearchIstopMessageList(table,userId) [NSString stringWithFormat:@"select * from %@ where toId <> '%@' and fromId = '%@' and isTop =  1",table,userId,userId]
//设置置顶联系人
#define kSetIstopContacts(table,userId,toId) [NSString stringWithFormat:@"SELECT * FROM %@ WHERE toId <> '%@' and toId = '%@' and fromId = '%@' and  isTop = 0 ;",table,userId,toId,userId]
//取消置顶联系人
#define kCancleIstopContacts(table,userId,toId) [NSString stringWithFormat:@"SELECT * FROM %@ WHERE toId <> '%@' and toId = '%@' and fromId = '%@' and  isTop = 1 ;",table,userId,toId,userId]
//查找所有联系人
#define kSearchContaces(table) [NSString stringWithFormat:@"SELECT * FROM %@;",table]
*/

#endif /* define_h */
